package com.mlog.njyjy.ndop.persistence.dao;

import com.mlog.njyjy.ndop.common.domain.Node;
import com.mlog.njyjy.ndop.share.sql.dao.BaseSqlRepository;
import com.mlog.njyjy.ndop.share.sql.support.SqlTableUtil;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author zyz
 * @version v1.0, 2020/8/18
 */
@Repository
public class NodeRepository extends BaseSqlRepository<Node> {

    /**
     * 根据节点名称和节点组获取节点对象
     *
     * @param name
     * @param groupId
     * @return
     */
    public Node findByNameAndGroup(String name, Long groupId) {

        List<Node> nodeList = find("select * from " + SqlTableUtil.getTblName(Node.class) + " where name=? and group_id = ?", name, groupId);
        if (nodeList != null && !nodeList.isEmpty()) {
            return nodeList.get(0);
        }
        return null;
    }
}
